<template>
	<view class="app">
		<view class="cell row b-b">
			<text class="tit">新密码</text>
			<input class="input" v-if="passwordFlg" type="text" maxlength="11" v-model="info.password" placeholder="请输入新密码" placeholder-class="placeholder" />
			<input class="input" v-else type="password" maxlength="11" v-model="info.password" placeholder="请输入新密码" placeholder-class="placeholder" />
			<text @tap="passwordFun()" class="mima iconfont " :class="passwordFlg?'iconmimakejian':'iconyincangmima'"></text>
		</view>
		<view class="cell row b-b">
			<text class="tit">再次输入</text>
			<input class="input" v-if="passwordReFlg" type="text" maxlength="100" v-model="info.passwordRe" placeholder="请再次输入新密码" placeholder-class="placeholder" />
			<input class="input" v-else type='password' maxlength="100" v-model="info.passwordRe" placeholder="请再次输入新密码" placeholder-class="placeholder" />
			<text @tap="passwordReFun()" class="mima iconfont" :class="passwordReFlg?'iconmimakejian':'iconyincangmima'"></text>
		</view>
		<!-- <view class="cell row b-b">
			<text class="tit fill">设为默认地址</text>
			<switch :checked="info.isDefault" color="#FF536F" @change="onSwitchChange" />
		</view> -->
		
		<view class="bot-btn-wrap fix-bot bg-none">
			<mix-button ref="confirmBtn" text="确认更改" icon="icon-jia2" :iconSize="36" :isConfirm="false" @onConfirm="submit()"></mix-button>
		</view>
		<tui-modal></tui-modal>
		<loading></loading>
	</view>
</template>

<script>
	import mixButton from '@/components/mix-button/mix-button.vue';
	export default {
		components: {
			mixButton
		},
		data() {
			return {
				info: {
					password:'',
					passwordRe:'',
				},
				
				passwordFlg:false,
				passwordReFlg:false,
				agencyId:'',
				btnFlg:false
			}
		},
		onLoad(options) {
			// #ifdef H5
			   this.$wechat.noShare();
			// #endif
			if(options){
				this.agencyId=options.agencyId
			}
		},
		methods: {
			passwordFun(){
				this.passwordFlg=!this.passwordFlg
			},
			passwordReFun(){
				this.passwordReFlg=!this.passwordReFlg
			},
			submit(){
				const data = this.info;
				if(!data.password){
					this.$util.msg('请输入新密码');
					this.$refs.confirmBtn.stop();
					return;
				}else if (!this.$util.checkStr(data.password, 'pwd')) {
					this.$util.msg('新密码长度在6~18之间，并由数字、字母组成');
					this.$refs.confirmBtn.stop();
					return;
				}
				
				if(!data.passwordRe){
					this.$util.msg('请再次输入新密码');
					this.$refs.confirmBtn.stop();
					return;
				}else if (!this.$util.checkStr(data.passwordRe, 'pwd')) {
					this.$util.msg('新密码长度在6~18之间，并由数字、字母组成');
					this.$refs.confirmBtn.stop();
					return;
				}
				if(data.password!==data.passwordRe){
					this.$util.msg('两次新密码输入不一致');
					this.$refs.confirmBtn.stop();
					return;
				}
				if(this.btnFlg){
					return;
				}
				let params=this.info;
				this.btnFlg=true
				params.agencyId=this.agencyId
					this.$http.registerInfoUpdate(params).then((res) => {
						if(res.status === 0) {
							uni.showToast({
								title: "密码修改成功!",
								icon: "none",
								duration: 500
							});
							setTimeout(() =>{
								uni.reLaunch({
									url: '/pages/home/login'
								})
								this.btnFlg=false
							},1000)
							this.$util.setToken('')
						}else{
							this.btnFlg=false
						}
					}).catch(() => {
						this.btnFlg=false
					})
			},
		}
	}
</script>

<style scoped lang="scss">
	.app{
		padding: 10rpx 36rpx 0;
		background-color: #fff;
		height: 100vh;
	}
	.cell{
		height: 106rpx;
		
		.tit{
			min-width: 140rpx;
			font-size: 28rpx;
			color: #111111;
		}
		.input{
			flex: 1;
			font-size: 28rpx;
			color: #333;
			border: none;
			outline: none;
		}
		.iconfont{
			flex-shrink: 0;
			margin-right: 8rpx;
			margin-left: 40rpx;
			font-size: 32rpx;
			color: #aaa;
		}
		switch{
			transform: scale(0.8) translateX(10rpx);
			transform-origin: center right;
		}
	}
</style>
